TestCase("AddControllerTest", {
	setUp: function () {
		this.view = document.createElement("form");
		this.view.appendChild(document.createElement("input"));
		this.view.appendChild(document.createElement("button"));
		this.backend = new tddjs.TodoList();
		this.listController = new tddjs.ListController()
		this.controller = new tddjs.AddController(this.view, this.backend, this.listController);
		this.backend = sinon.mock(this.backend);
		this.listController = sinon.mock(this.listController);
	},
	"test add TDD" : function() {
		this.backend.expects("add").withArgs("TDD").once().yields();
		this.listController.expects("taskAdded").withArgs("TDD").once();

		this.view.childNodes[0].setAttribute("value", "TDD");
		jQuery(this.view.childNodes[1]).trigger("click");

		this.backend.verify();
		this.listController.verify();
		assertEquals("", this.view.childNodes[0].getAttribute("value"));
	} ,
	"test add BDD" : function() {
		this.backend.expects("add").withArgs("BDD").once().yields();
		this.listController.expects("taskAdded").withArgs("BDD").once();

		this.view.childNodes[0].setAttribute("value", "BDD");
		jQuery(this.view.childNodes[1]).trigger("click");

		this.backend.verify();
		this.listController.verify();
		assertEquals("", this.view.childNodes[0].getAttribute("value"));
	} ,
	"test add is unsuccesfull" : function() {
		this.backend.expects("add").withArgs("BDD").once().yields({message:"server bad"});
		this.listController.expects("taskAdded").never();

		this.view.childNodes[0].setAttribute("value", "BDD");
		jQuery(this.view.childNodes[1]).trigger("click");

		this.backend.verify();
	}	
});